package com.OctTwentyFour;

import java.util.Arrays;

/**
 *
 * 面试题 16.01. 交换数字
 * 编写一个函数，不用临时变量，直接交换numbers = [a, b]中a与b的值。
 * https://leetcode.cn/problems/swap-numbers-lcci/
 *
 * 2022/10/24 23:53
 */

public class Solution16_01 {

    public int[] swapNumbers(int[] numbers) {
        numbers[0]=numbers[0]^numbers[1];
        numbers[1]=numbers[1]^numbers[0];
        numbers[0]=numbers[1]^numbers[0];
        return numbers;
    }

    public static void main(String[] args) {
        Solution16_01 solution16_01=new Solution16_01();
        System.out.println(Arrays.toString(solution16_01.swapNumbers(new int[]{1, 2})));
    }

}
